package com.youlin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youlin.dto.BaseDataResDto;
import com.youlin.dto.Status;
import com.youlin.entities.BygSignInTemplate;
import com.youlin.mapper.BygSignInTemplateMapper;
import com.youlin.service.BygSignInTemplateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlin.untils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class BygSignInTemplateServiceImpl extends ServiceImpl<BygSignInTemplateMapper, BygSignInTemplate> implements BygSignInTemplateService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public BaseDataResDto<List<BygSignInTemplate>> findAllSiTemps() {
        List<BygSignInTemplate> allSiTemps = RedisUtil.getList(redisTemplate, "allSiTemps", BygSignInTemplate.class);
        if (allSiTemps == null) {
            synchronized (this) {
                allSiTemps = RedisUtil.getList(redisTemplate, "allSiTemps", BygSignInTemplate.class);
                if (allSiTemps == null) {
                    allSiTemps = list(new QueryWrapper<BygSignInTemplate>().orderByAsc("no"));
                    RedisUtil.setObjectExpire(redisTemplate, "allSiTemps", allSiTemps);
                }
            }
        }
        return new BaseDataResDto<List<BygSignInTemplate>>(Status.SUCCESS).setData(allSiTemps);
    }
}
